<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>添加作品</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="${pageContext.request.contextPath }/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <!-- jqgrid-->
    <link href="${pageContext.request.contextPath }/css/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/animate.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/style.css?v=4.1.0" rel="stylesheet">
    <script src="${pageContext.request.contextPath }/js/jquery.min.js?v=2.1.4"></script>
    <script src="${pageContext.request.contextPath }/js/bootstrap.min.js?v=3.3.6"></script>
    
    <!-- 自定义js -->
    <script src="${pageContext.request.contextPath }/js/content.js?v=1.0.0"></script>
    <!-- jQuery Validation plugin javascript-->
    <script src="${pageContext.request.contextPath }/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/plugins/validate/messages_zh.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/plugins/layer/layer.min.js"></script>
	<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=C75HGmvnjDq1Fer37Mrkw24YfBKyQKI9"></script>
    
	<style>
		input,select{
			 width:168px;
			 height:25px;
			 border:1px solid #ccc;
			 margin-left:24px;
		}
		
		.form-item{
			display:flex;
		}
		.label-text{
		   height: 34px;
		   line-height: 34px;
		   font-weight: normal;
		}
		.addInput{ 
			background-color: #ffffff;
		    background-image: none;
		    border: 1px solid #e5e6e7;
		    border-radius: 1px;
		    color: inherit;
		    display: block;
		    font-size: 14px;
		    padding: 6px 12px;
		    transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s;
		    height: 34px;
		   line-height: 34px;
		   flex: 1;
		}
		.saveBtn{
			 display: block;
		    margin: 15px auto;
		    width: 120px;
		}

		#allmap {
			height: 500px;
			width: 100%;
		}
		
		#r-result {
			width: 100%;
			font-size: 14px;
		}
	</style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content  animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox ">
                    <div class="ibox-content">
                        <div class="form-inline">
	                       	<c:forEach items="${al }" var="list" varStatus="status">
	                       		经度：<input type = "text" value = "${list.lat }"/>
	                       		纬度：<input type = "text" value = "${list.lng }"/>
	                       		<button onclick="deleted(${list.id})" type="submit">删除</button>
	                       		<br/>
							</c:forEach>
							<form name = "form1" id = "add_area_list"  enctype='multipart/form-data'>
								<input type = "hidden"  name = "areaId" value = "${a.id }" ><br/><br/>
								<div id="allmap"></div>
								<div class="form-item">
									<label  class="label-text">地址:</label>
									 <input id="cityName" type="text"style="width: 100px; margin-right: 10px;" /> 
									<input type="button" value="查询" onclick="theLocation()" /><br/><br/>   
								</div>
								
								<div class="form-item">
									<label class="label-text">经度：</label>
									<input type = "text" class = "addInput" id = "lat" name = "lat" maxlength="20" ><br/><br/>
								</div>	
								<div class="form-item">
									<label class="label-text">纬度：</label>
									<input type = "text" class = "addInput" id = "lng" name = "lng" maxlength="20" ><br/><br/>
								</div>	
								<button class="btn btn-primary saveBtn" type="submit">保存</button>
						    </form>
						</div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</body>

	<script type="text/javascript">


	// 百度地图API功能
	var map = new BMap.Map("allmap");	
	var points = [];
	map.addEventListener("click", function(e) {
		var input = document.getElementById('lng');
		var input2 = document.getElementById('lat');
		input.value = e.point.lng;
		input2.value = e.point.lat;
	});
 	<c:forEach items="${al}" var="item" varStatus="status" >
		points['${status.index}'] = new BMap.Point('${item.lng}', '${item.lat}');
	</c:forEach> 
	map.centerAndZoom(new BMap.Point('${a.lng}','${a.lat}'), 16);
	map.enableScrollWheelZoom(true);
	//搜索
	function theLocation() {
		var city = document.getElementById("cityName").value;
		if (city != "") {
			local.search(city);
		}
	}

	var local = new BMap.LocalSearch(map, {
		renderOptions : {
			map : map
		}
	});
	for(var i = 0; i<points.length; i++){
		var marker = new BMap.Marker(points[i]);
		map.addOverlay(marker);
	}
	
	
	
	
    
 	// 手机号码验证  
    jQuery.validator.addMethod("isMobile", function(value,element) {
        var length = value.length;
        var mobile =  /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(14[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
        var tel = /^\d{3,4}-?\d{7,9}$/;
        if(/-/.test(value)){
            return this.optional(element) || tel.test(value);
        }else{
            return this.optional(element) || (length == 11 && mobile.test(value));
        }

    }, "请正确填写您的联系电话");
 
    $().ready(function () {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#add_area_list").validate({
            rules: {
                lat: {//纬度
                    required: true,
    				maxlength: 100
                },
                lng: {//经度
                    required: true,
    				maxlength: 100
                }
            },
            messages: {
                lat:{
            		required:icon + "请填写经度",
            		maxlength:icon + "最大长度为100"
            		},
                lng:{
            		required:icon + "请填写纬度",
            		maxlength:icon + "最大长度为100"
            		}
                
            },
    		submitHandler: function(form) {
    			addBuildingList();
    		}
        });
    });

    function cancel(){
 		var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        parent.layer.close(index);
 	}
	 function ValidateValue(textbox)
     {
          var IllegalString = "\`~@#;,.!#$%^&*()+{}|\\:\"<>?-=/,\' []";
          var textboxvalue = textbox.value;
          var index = textboxvalue.length - 1;
          
          var s = textbox.value.charAt(index);
          
          if(IllegalString.indexOf(s)>=0)
          {
             s = textboxvalue.substring(0,index);
             textbox.value = s;
          }
     }


    //上传图片
    function imageChange(target) {
        var fileSize = 0;
        fileSize = target.files[0].size;
        var size = fileSize / 1024;
        if(size > 2000){
           alert("图片不能大于2M");
           target.value="";
           return false;   //阻止submit提交
        }
        var name=target.value;
        var fileName = name.substring(name.lastIndexOf(".")+1).toLowerCase();
        if(fileName !="jpg" && fileName !="jpeg" && fileName !="png"){
           alert("请选择图片格式文件上传(jpg,jpeg,png)！");
           target.value="";
           return false;   //阻止submit提交
        }
	}
    //上传视频
    function videoChange(target) {
        var name=target.value;
        var fileName = name.substring(name.lastIndexOf(".")+1).toLowerCase();
        if(fileName !="mp4"){
           alert("请选择图片格式文件上传(.mp4格式)！");
           target.value="";
           return false;   //阻止submit提交
        }
	}
 
	//添加或修改
	function addBuildingList(){	
		var formData = new FormData($( "#add_area_list" )[0]);  
		$.ajax({
			processData: false,
			contentType: false,
    		url:"${pageContext.request.contextPath }/admin/areaList/add",
    		data:formData,
    		type:"post",
    		success:function(data){
    			if(data.code == 0){
					layer.msg(data.message,{icon:1});
					window.location.reload();
    			}else {
					layer.msg(data.message,{icon:0});
    			}
    		}
    	});
	}
	
	function deleted(id){
		$.ajax({
			processData: false,
			contentType: false,
    		url:"${pageContext.request.contextPath }/admin/areaList/deleted/" + id,
    		type:"post",
    		success:function(data){
    			if(data.code == 0){
					layer.msg(data.message,{icon:1});
					window.location.reload();
    			}else {
					layer.msg(data.message,{icon:0});
    			}
    		}
    	});
	}
	</script>
</html>
